﻿<%@ Page Title="" Language="C#" MasterPageFile="~/backend/MasterPage_backend.master" AutoEventWireup="true" CodeFile="Staff.aspx.cs" Inherits="Staff" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<!-- header-starts -->
			<div class="header-section">
				</div>
				<div class="header_bg">					
							<div class="header">
								<div class="head-t">
									<div class="logo">
										<a href="index.html"><img src="images/logo.png" class="img-responsive" alt=""> </a>
									</div>
										<!-- start header_right -->
									<div class="header_right">
										<div class="rgt-bottom">
										<div class="cart box_1">
											<a href="#">
												<h3> <span class="simpleCart_total">员工管理系统 SalaryManagement</span></h3>
											</a>	
                                            <p>&nbsp;</p>
											<div class="clearfix"> </div>
										</div>
										<div class="clearfix"> </div>
									</div>
									<div class="search">
										<form>
											<input type="text" value="" placeholder="search...">
											<input type="submit" value="">
										</form>
									</div>
									<div class="clearfix"> </div>
								</div>
								<div class="clearfix"> </div>
							</div>
						</div>
					
				</div>
					<!-- //header-ends -->
    <div class="content">
        <div class="fo-top-di">
        <%--上部信息--%>
	        <div class="foot-top" >
                <div id=" " class="menu" >
                部门 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            DataSourceID="DpDS" DataTextField="DpName" DataValueField="DpNo"   >
        </asp:DropDownList>
                    职位<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" 
            DataSourceID="PosDS" DataTextField="PosName" DataValueField="PosNo" >
        </asp:DropDownList>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
		        <asp:Button ID="Button1" runat="server" Text="添加新员工" onclick="Button1_Click"/> &nbsp; &nbsp; 
                <asp:Button ID="Button2" runat="server" Text="取消添加" onclick="Button2_Click"  />
		       
                </div>
        <asp:SqlDataSource ID="DpDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:HotelManagementConnectionString %>" 
            SelectCommand="SELECT * FROM [Department]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="PosDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:HotelManagementConnectionString %>" 
            SelectCommand="SELECT * FROM [Position] WHERE ([DpNo] = @DpNo)">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="DpNo" 
                    PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
                </asp:SqlDataSource>
                <asp:Panel ID="Panel1" runat="server" Visible="False">
                 <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                    DataKeyNames="SNo" DataSourceID="StaffDS2" DefaultMode="Insert" Height="50px" 
                    HorizontalAlign="Center" Width="100%" 
                        onpageindexchanging="DetailsView1_PageIndexChanging">
                    <Fields>
                        <asp:BoundField DataField="SNo" HeaderText="员工号" InsertVisible="False" 
                            ReadOnly="True" SortExpression="SNo" />
                        <asp:BoundField DataField="SName" HeaderText="姓名" SortExpression="SName" />
                        <asp:TemplateField HeaderText="部门" SortExpression="DpNo">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DpNo") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True" 
                                    DataSourceID="DpDS2" DataTextField="DpName" DataValueField="DpNo" 
                                    SelectedValue='<%# Bind("DpNo") %>'>
                                </asp:DropDownList>
                                <asp:SqlDataSource ID="DpDS2" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:HotelManagementConnectionString %>" 
                                    SelectCommand="SELECT * FROM [Department]"></asp:SqlDataSource>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("DpNo") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="职位" SortExpression="PosNo">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("PosNo") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:DropDownList ID="DropDownList5" runat="server" AutoPostBack="True" 
                                    DataSourceID="PosDS2" DataTextField="PosName" DataValueField="PosNo" 
                                    SelectedValue='<%# Bind("PosNo") %>'>
                                </asp:DropDownList>
                                <asp:SqlDataSource ID="PosDS2" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:HotelManagementConnectionString %>" 
                                    SelectCommand="SELECT * FROM [Position]"></asp:SqlDataSource>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("PosNo") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="STelphone" HeaderText="电话" 
                            SortExpression="STelphone" />
                        <asp:CommandField ShowInsertButton="True" />
                    </Fields>
                </asp:DetailsView>
                <asp:SqlDataSource ID="StaffDS2" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:HotelManagementConnectionString %>" 
                    InsertCommand="insert into Staff(SName,DpNo,PosNo,STelphone)values(@SName,@DpNo,@PosNo,@STelphone)" 
                    SelectCommand="SELECT * FROM [Staff]">
                    <InsertParameters>
                        <asp:Parameter Name="SName" />
                        <asp:Parameter Name="DpNo" />
                        <asp:Parameter Name="PosNo" />
                        <asp:Parameter Name="STelphone" />
                    </InsertParameters>
                </asp:SqlDataSource>
                </asp:Panel>
		       
                <br />
		    </div>
       <%--下部信息--%>
            <div class="footer">
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        CellPadding="4" DataKeyNames="SNo" DataSourceID="StaffDS" ForeColor="#333333" 
        GridLines="None" Width="100%" 
        style="text-align: center">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:BoundField DataField="SNo" HeaderText="员工编号" InsertVisible="False" 
                ReadOnly="True" SortExpression="SNo" />
            <asp:BoundField DataField="SName" HeaderText="员工姓名" SortExpression="SName" />
            <asp:TemplateField HeaderText="部门" SortExpression="DpNo">
                <EditItemTemplate>
                    <asp:DropDownList ID="DpDepartment" runat="server" DataSourceID="DpDS" 
                        DataTextField="DpName" DataValueField="DpNo" 
                        SelectedValue='<%# Bind("DpNo") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("DpName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="职位" SortExpression="PosNo">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="PosDS2" 
                        DataTextField="PosName" DataValueField="PosNo" 
                        SelectedValue='<%# Bind("PosNo") %>'>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="PosDS2" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:HotelManagementConnectionString %>" 
                        SelectCommand="SELECT * FROM [Position]"></asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("PosName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="STelphone" HeaderText="电话" 
                SortExpression="STelphone" />
            <asp:CommandField EditText="更改信息" HeaderText="操作" ShowDeleteButton="True" 
                ShowEditButton="True" />
        </Columns>
        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
        <SortedAscendingCellStyle BackColor="#FDF5AC" />
        <SortedAscendingHeaderStyle BackColor="#4D0000" />
        <SortedDescendingCellStyle BackColor="#FCF6C0" />
        <SortedDescendingHeaderStyle BackColor="#820000" />
    </asp:GridView>
    <asp:SqlDataSource ID="StaffDS" runat="server" 
        ConnectionString="<%$ ConnectionStrings:HotelManagementConnectionString %>" 
        
        SelectCommand="SELECT Staff.SNo, Staff.SName, Staff.DpNo, Staff.PosNo, Staff.STelphone, Department.DpName, Position.PosName FROM Staff INNER JOIN Department ON Staff.DpNo = Department.DpNo INNER JOIN Position ON Staff.PosNo = Position.PosNo WHERE (Staff.DpNo = @DpNo) AND (Staff.PosNo = @PosNo)" 
        DeleteCommand="DELETE FROM Staff WHERE (SNo=@SNo)" 
        
        UpdateCommand="UPDATE Staff SET SName = @SName, DpNo = @DpNo, PosNo = @PosNo, STelphone = @STelphone WHERE (SNo = @SNo)" 
        InsertCommand="INSERT INTO Staff(SName,DpNo,PosNo,STelphone)VALUES (@SName,@DpNo,@PosNo,@STelphone)">
        <DeleteParameters>
            <asp:Parameter Name="SNo" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="SName" />
            <asp:Parameter Name="DpNo" />
            <asp:Parameter Name="PosNo" />
            <asp:Parameter Name="STelphone" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="DpNo" 
                PropertyName="SelectedValue" Type="String" />
            <asp:ControlParameter ControlID="DropDownList2" Name="PosNo" 
                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="SName" />
            <asp:Parameter Name="DpNo" />
            <asp:Parameter Name="PosNo" />
            <asp:Parameter Name="STelphone" />
            <asp:Parameter Name="SNo" />
        </UpdateParameters>
    </asp:SqlDataSource>
		             <p>@ 2017 HotelManagement. All Rights Reserved | Design by <a href="#">us</a></p>
            </div>
        </div>
    </div>
</asp:Content>

